<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <title>排刀</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <link rel="stylesheet" href="../css/style.css">

</head>
<body>
<div>
    <ul class="layui-nav">
        <li class="layui-nav-item"><a href="/pd.html">排刀功能</a></li>
        <li class="layui-nav-item"><a href="/Lineup.html">轴资料</a></li>
        <li class="layui-nav-item"><a href="/Box.html">box资料</a></li>
        <li class="layui-nav-item layui-this"><a href="/param.html">参数设置</a></li>
    </ul>
</div>
<div>
    <ul class="layui-nav">
    </ul>
</div>
<div class="demoTable" style="margin-top: 20px;text-align: right;">
    <button class="layui-btn" id="initParam">初始化参数</button>
    <button class="layui-btn" id="calParam">自动优化权重</button>
</div>

<table class="layui-hide" id="test" lay-filter="test"></table>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="update">更新</a>
</script>

<script src="layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script src="./js/mainmenu.js" charset="utf-8"></script>
<script>
    layui.use(['table','jquery'], function(){
        var table = layui.table;
        var $ = layui.jquery;

        table.render({
            elem: '#test'
            ,url:'/box/getAllParam'
            ,title: '参数表'
            ,headers:{ token: window.sessionStorage.getItem('token') }
            ,cols: [[
                {field:'id', title:'ID', fixed: 'left', unresize: true, sort: true, hide:true}
                ,{field:'paramKey', title:'key'}
                ,{field:'paramValue', title:'value', edit: 'text'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:'10%'}
            ]]
            ,id: 'testReload'
        });

        //监听工具条
        table.on('tool(test)', function(obj) {
            var data = obj.data;
            if (obj.event === 'update') {
                $.ajax({
                    url:"/box/updateParam",
                    type: "POST",
                    datType: "JSON",
                    contentType: "application/json",
                    headers:{ token: window.sessionStorage.getItem('token') },
                    data: JSON.stringify(data),
                    success:function(result){
                        if (result.code == 0) {
                            parent.location.reload()
                        }else{
                            layer.alert("异常错误:"+result.message)
                        }
                    },
                    error: function () {
                        layer.alert("请求失败，请联系管理员")
                    }
                })
            }
        })
        $('#initParam').on('click', function(){
            $.ajax({
                url:"/box/initParam",
                type: "POST",
                datType: "JSON",
                contentType: "application/json",
                headers:{ token: window.sessionStorage.getItem('token') },
                success:function(result){
                    if (result.code == 0) {
                        parent.location.reload()
                    }else{
                        layer.alert("异常错误:"+result.message)
                    }
                },
                error: function () {
                    layer.alert("请求失败，请联系管理员")
                }
            })
        });
        $('#calParam').on('click', function(){
            $.ajax({
                url:"/box/calParam",
                type: "POST",
                datType: "JSON",
                contentType: "application/json",
                headers:{ token: window.sessionStorage.getItem('token') },
                success:function(result){
                    if (result.code == 0) {
                        parent.location.reload()
                    }else{
                        layer.alert("异常错误:"+result.message)
                    }
                },
                error: function () {
                    layer.alert("请求失败，请联系管理员")
                }
            })
        });
    });
</script>

</body>
</html>